﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JY.Common.Configurations
{
    /// <summary>
    /// 实体配置节点
    /// </summary>
    public class EntitySection : ConfigurationSection
    {
        #region # 字段及构造器

        /// <summary>
        /// 单例
        /// </summary>
        private static readonly EntitySection _Setting;

        /// <summary>
        /// 静态构造器
        /// </summary>
        static EntitySection()
        {
            _Setting = (EntitySection)ConfigurationManager.GetSection("jy.entity");

            #region # 非空验证

            if (_Setting == null)
            {
                throw new ApplicationException("jy.entity节点未配置，请检查程序！");
            }

            #endregion
        }

        #endregion

        #region # 访问器 —— static EntitySection Setting
        /// <summary>
        /// 访问器
        /// </summary>
        public static EntitySection Setting
        {
            get { return _Setting; }
        }
        #endregion

        #region # 实体所在程序集节点 —— TextElement EntityAssembly
        /// <summary>
        /// 实体所在程序集节点
        /// </summary>
        [ConfigurationProperty("entity.assembly", IsRequired = false)]
        public TextElement EntityAssembly
        {
            get { return (TextElement)this["entity.assembly"]; }
            set { this["entity.assembly"] = value; }
        }
        #endregion

        #region # 实体配置所在程序集节点 —— TextElement EntityConfigAssembly
        /// <summary>
        /// 实体配置所在程序集节点
        /// </summary>
        [ConfigurationProperty("entity.config.assembly", IsRequired = false)]
        public TextElement EntityConfigAssembly
        {
            get { return (TextElement)this["entity.config.assembly"]; }
            set { this["entity.config.assembly"] = value; }
        }
        #endregion

        #region # 实体数据表名前缀节点 —— TextElement EntityTablePrefix
        /// <summary>
        /// 实体数据表名前缀节点
        /// </summary>
        [ConfigurationProperty("entity.tablePrefix", IsRequired = false)]
        public TextElement EntityTablePrefix
        {
            get { return (TextElement)this["entity.tablePrefix"]; }
            set { this["entity.tablePrefix"] = value; }
        }
        #endregion
    }
}
